﻿@using Ext.Net.MVC;
@using Ext.Net;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Header
{
    <script>
        function deleterecord() {
            if (App.DataGridPanel.getSelectionModel().getSelection()[0] == null) {
                alert('No contact selected');
                return;
            }
            var id = App.DataGridPanel.getSelectionModel().getSelection()[0].get('Forumn');
        }

        function editrecord() {
            if (App.ForumDataGrid.getSelectionModel().getSelection()[0] == null) {
                alert('No record selected');
                return;
            }
            var id = App.ForumDataGrid.getSelectionModel().getSelection()[0].get('ForumId');
            showWindow('Edit Forum', '/Forum/Edit/' + id, true, 0.85, 0.85);

        }

        function search() {
            App.direct.Search;
  
        }
    </script>
    
    
}

@section ToolbarSection
{
    @Html.X().Button().Text("Create").Icon(Icon.ControlAddBlue).Listeners(ls => ls.Click.Handler = "showWindow('Create Forum','/Forum/Create/',true,0.85,0.85);")
}
@Html.X().FormPanel().Border(false).ID("SearchForm").Items(
Html.X().Toolbar().Items(
            Html.X().ToolbarTextItem().Text("Search:").Flex(1),
            Html.X().TextField().ID("txtCateName").EmptyText("Input Category Name").Flex(2).Listeners(ls=>ls.KeyDown.Handler="search"),
            Html.X().TextField().ID("txtTypeName").EmptyText("Input Forum Type").Flex(2).Listeners(ls=>ls.KeyDown.Handler="search"),
            Html.X().TextField().ID("txtForumName").EmptyText("Input Forum Name").Flex(2).Listeners(ls=>ls.KeyDown.Handler="search"),
            Html.X().TextField().ID("txtForumDescription").EmptyText("Input Forum Description").Flex(6).Listeners(ls=>ls.KeyDown.Handler="search"),
            Html.X().Button().ID("btnSearch").Text("Search").Margins("0 0 0 10").Icon(Icon.Find).DirectEvents(
            de =>
            {
                de.Click.Url = Url.Action("Search");
                de.Click.FormID = "SearchForm";
            }).Flex(1),
            Html.X().Button().Text("None").Margins("0 0 0 10").Icon(Icon.Erase).DirectEvents(
                de =>
                {
                    de.Click.Url = Url.Action("ClearSearch");
                    de.Click.FormID = "SearchForm";
                }).Flex(1)
            )
        )
@* GridPanel *@
@(Html.X().GridPanel()
      .ID("ForumDataGrid")
      .Frame(true)
      .Border(false)
      .Store(
          Html.X().Store()
              .ID("ForumDataStore")
              .Model(
                  Html.X().Model()
                      .IDProperty("ForumId")
                      .Fields(
                          new ModelField("ForumId",ModelFieldType.Int),
                          new ModelField("CateName"),
                          new ModelField("TypeName"),
                          new ModelField("ForumName"),
                          new ModelField("Description"),
                          new ModelField("DateCreate"),
                          new ModelField("IsActive")
                             )
                    )
               .RemoteSort(true)
               .RemotePaging(true)
               .RemoteFilter(true)
               .PageSize(10)
               .Proxy(
                      Html.X().AjaxProxy()
                              .Url(Url.Action("ForumData"))
                              .Reader(Html.X().JsonReader().Root("data"))
                     )
            )
      .ColumnModel(
          Html.X().Column().Text("ID").DataIndex("ForumId").Flex(1),
          Html.X().Column().Text("Category").DataIndex("CateName").Flex(2),
          Html.X().Column().Text("Type").DataIndex("TypeName").Flex(2),
          Html.X().Column().Text("Name").DataIndex("ForumName").Flex(2),
          Html.X().Column().Text("Description").DataIndex("Description").Sortable(false).Flex(3),
          Html.X().Column().Text("Date Create").DataIndex("DateCreate").Flex(2),
          Html.X().Column().Text("Is Active?").DataIndex("IsActive").Flex(1),
          Html.X().CommandColumn().Text("Edit").Commands(
          Html.X().GridCommand().CommandName("Edit").Icon(Icon.NoteEdit).ToolTip(tt => tt.Text = "Edit Record"))
                .Listeners(ls => ls.Command.Handler = "editrecord();").Flex(1),
          Html.X().CommandColumn().Text("Delete").Commands(
          Html.X().GridCommand().CommandName("Delete").Icon(Icon.Delete).ToolTip(tt => tt.Text = "Delete Record"))
                .Listeners(ls => ls.Command.Handler = "deleterecord();").Flex(1)
                   )
          .BottomBar(Html.X().PagingToolbar()))